import Antd, { message } from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';

const test = function(value) {
    this.pattern.lastIndex = 0;
    return this.pattern.test(value)
}
export const _rules = {
    mobilePhone: {
        pattern: /^1(3\d|4[01|4-9]|5[0-3|5-9]|6[5-7]|7[0-8]|8\d|9[89])\d{8}$/,
        message: '手机号码不正确',
        test
    },
    account: {
        pattern: /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/ig,
        message: '邮箱不合法！',
        test,
        validator: async(_rule, value) => {
            if (value === '') return Promise.reject('邮箱不能为空！')
            if (_rules.account.test(value)) {
                return Promise.resolve()
            } else return Promise.reject(_rules.account.message)
        }
    },
    password: {
        pattern: /^(?=.*\d)(?=.*[a-zA-Z])[\da-zA-Z~!@#$%^&*]{6,18}$/,
        message: '密码长度6到18位，且必须包含数字及英文',
        messageSecond: '密码不能为空！',
        test
    },
    emailCode: {
        message: '验证码不能为空！'
    },
}

export function loading(content) {
    message.loading(content, 1);
}
export function success(content, onClose = null) {
    message.success({
        content,
        duration: 2,
        onClose
    });
}
export function warning(content) {
    message.warning(content, 1)
}
export function destroy() {
    message.destroy()
}
export default Antd;